<?
// +----------------------------------------------------------------------
// | 分销联盟-联盟信息管理页面
// +----------------------------------------------------------------------
// | Author: TongBC <50249101@qq.com>
// +----------------------------------------------------------------------
// | Date  : 2015/03/06
// +----------------------------------------------------------------------
include_once("common/header.html");
include_once("common/left.html");
include_once("common/areaCode.inc.php");
include_once("class/MemberAccount.class.php");
include_once("class/Alliance.class.php");

if(empty($_SESSION['alliance'])) exit("<script>window.location='home.html'</script>");
$memberID = $_SESSION['sid'];
$mem = new \pft\Member\MemberAccount($GLOBALS['le']);
$m_info = $mem->GetOne($memberID);
$a_info = Alliance::info($memberID);

$dratio = explode('|', $a_info['dratio']);



// 获取当前已指定的代理商
$sql="select d.darea_title,d.dtime,m.dname from pft_distributor_agency d left join pft_member m on d.inviterID=m.id where fid=$memberID";
$GLOBALS['le']->query($sql);
while($row=$GLOBALS['le']->fetch_assoc()){
    $exiagent[] = $row;
}

// 加入联盟的分销商才可指定代理商
$sql="select m.id,m.dname,getPY(m.dname,1) as py from pft_member m left join pft_union_member_info_SE s on m.id=s.memberID where fid=$memberID order by py";
$select1 = '<select style="width:160px" name="city_agent[]" class="agents"><option value="0">请选择代理商</option>';
$select2 = '<select style="width:120px"><option value="0">请选择代理商</option>';
$GLOBALS['le']->query($sql);
while($row = $GLOBALS['le']->fetch_assoc()){
	if(empty($row['dname'])) continue;
    $select1.='<option value="'.$row['id'].'">'.$row['py'].'-'.$row['dname'].'</option>';
    $select2.='<option value="'.$row['id'].'">'.$row['py'].'-'.$row['dname'].'</option>';
}
$select1.='</select>';
$select2.='</select>';

$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:50;
$txt=$_REQUEST['txt'];
$dtype=$_REQUEST['dtype'];
$ctype=$_REQUEST['com_type'];
$prov=$_REQUEST['d_province']?$_REQUEST['d_province']:0;
$city=$_REQUEST['d_city']?$_REQUEST['d_city']:0;
$disList=array();
if($txt && $txt!="请输入企业名称\分销账号\手机"){
	$tj=" and (instr(dname,'".$txt."') or instr(cname,'".$txt."') or account='".$txt."' or mobile='".$txt."')";
}
if($prov || $city || $ctype){
	$a_t=" left join pft_member_extinfo e on e.fid=m.id ";
	$a_tj.=$prov?" and province=".$prov:"";
	$a_tj.=$city?" and city=".$city:"";
	if($ctype){
		$a_tj.=" and (";
		foreach($ctype as $v){
			$a_tj.="instr(com_type,'".$v."') or ";
		}
		$a_tj=trim($a_tj,"or ").")";
	}
}
// 获取分销商
// $sel1 = "select m.id,m.dname from pft_member_relationship r left join pft_member m on m.id=son_id where r.parent_id=$memberID and r.status=0 and ship_type=0 and m.status in (0,3)";
// $GLOBALS['le']->query($sel1);
// while($row=$GLOBALS['le']->fetch_assoc()){
	// $disList[$row['id']]=$row;
// }
$sel1="select dname,cname,account,mobile,m.id,son_id_type,ship_type,u.dstatus ";
$sel2="select count(*) total ";
$sel="from pft_member_relationship r left join pft_member m on m.id=son_id left join (select memberID,dstatus from pft_union_member_info_SE where fid={$_SESSION['sid']}) u ON m.id =u.memberID ".$a_t." where m.status in (0,3) ".$tj.$a_tj." and r.status=0 and parent_id=".$_SESSION['sid']." and ship_type=0";
$GLOBALS['le']->query($sel1.$sel." limit ".($currentPage-1)*$pageSize.",".$pageSize);
while($row=$GLOBALS['le']->fetch_assoc()){
	$disList[$row['id']]=$row;
}


// 获取省份
$sql="select * from `pft_area_code_concat` where parent_province=n_code";
$GLOBALS['le']->query($sql);
while($row = $GLOBALS['le']->fetch_assoc()){
	$province[] = $row;
}
include('tpl/alliance_test.html');
include("common/footer.html");
exit;
?>
<title><?=$v['title']?></title>
<script src="js/ui/PopWindow.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/default.css"/>
<link rel="stylesheet" type="text/css" href="css/page.css"/>
<link rel="stylesheet" type="text/css" href="css/alliance_f.css" />
<link rel="stylesheet" type="text/css" href="css/buyProduct.css" />'

<div class="rigArea"> 
<div style="display:none;" id="hideSetion">
<?=$select1;?>
</div>
<div class="topTit"><span class="txt"><strong>联盟配置</strong></span></div>
<iframe name="ifr" style="display:none;"></iframe>


<div class="ui-c-box">
    <p class="ui-line">
        <span class="ui-title">添加代理商配置：</span>        
        <span >
            <select class="ui-select province">
                <option>请选择代理省份</option>
                <?foreach($areaCode as $k => $province):?>
                <option value="<?=$k?>"><?=$province['title']?></option>
                <?endforeach;?>
            </select>
        </span>
		</br>
		<span class="ui-title">已配置的代理商：</span>
    </p>
    <style type="text/css">
    .ui-t-list{border:1px solid #ccc;margin:10px 0;width:725px;}
    .ui-t-list tr:hover{background:#F7F7D1;}
    .ui-t-list .head,.ui-t-list .head:hover{font-weight:normal;color:#000;background:#e5e5e5;}
    .ui-t-list td.w1,td.w2{width:10%;white-space:nowrap;word-break:keep-all;font-weight:bold;}
    .ui-t-list td.w2{color:#FFF;background:#254E75;}
    .ui-t-list td{padding:5px 10px;vertical-align:top;vertical-align:middle;font-size:14px;text-align: center;}
    .ui-t-list a{color:#519CEA;}
    .ui-t-list a:hover{text-decoration:underline;}
    </style>
    <?if(count($exiagent)):?>
    <div class="list-agent">
    <table class="ui-t-list" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr class="head"><td >代理市</td><td>代理商</td><td>指定时间</td><td>操作</td></tr>
        <?foreach($exiagent as $at):?>
        <tr><td class="w1"><?=$at['darea_title']?></td><td><?=$at['dname']?></td><td><?=$at['dtime']?></td><td><a href="#">删除</a></td></tr>
        <?endforeach;?>
    </tbody>
    </table>
    </div>
    <?endif;?>
    <div class="listWrap">
        <ul id="mlistUl" class="listUl">
           
            <li><input type="submit" class="d_save" value="保存"></li>
        </ul>
    </div>
</div>
</form>
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	<!--
	<form action="call/jh_alliance.php" method="post" target="ifr" id="step1">
	<div class="degcon">
		<input type="hidden" name="uid" value="<?=$a_info['id']?>" />
		<input type="hidden" name="action" value="modify"/>
		<p><b>联盟名称：</b><span><input type="text" class="inptxt wid270"  name="aname" value="<?=$a_info['dtitle']?>" /></span></p>
		<p>利润比例：平台<input class="pinput-txt_b" type="text" name="profit_a" value="15">% 供应商<input class="pinput-txt_b" type="text" name="profit_b" value="20">% 联盟<input class="pinput-txt_b" type="text" name="profit_x">% 邀请人<input class="pinput-txt_b" type="text" name="profit_y">% </p>
        <p>联盟分配：盟主<input class="pinput-txt_b" type="text" name="profit_c" value="25">% 省代理<input class="pinput-txt_b" type="text" name="profit_d" value="15">% 市代理<input class="pinput-txt_b" type="text" name="profit_e" value="10">% </p>
		<p>邀请人分配：上级邀请人<input class="pinput-txt_b" type="text" name="profit_f" value="10">% 邀请人<input class="pinput-txt_b" type="text" name="profit_g" value="5">%</p>
	</div>
	<div style="clear:both;"><input type="submit" class="l_save_f" value="保存" /></div>
	</form>
	-->

	<?//page($count,$currentPage,$pageSize,$order,$by);?>
</div>
<div id="dialog1">
    <p class="close"><a href="javascript:close();">关闭</a>
    <div class="ui-content"></div>
</div>
<script type="text/javascript">
function close(){
	$("#fullbg,#dialog,#dialog1").hide();
}
$(document).ready(function(){
    
    $(".province").change(function(){
		var _this = $(this),flag = false,_html = '';
		// $("#fullbg").css({height:$("html").height(), width:$("html").width(), display:"block" });
        // $("#dialog1").show();

        // $(".selected").each(function(){
            // if($(this).attr("data")==_this.val()) flag = true;
        // });
		

        $.getJSON('call/jh_alliance.php',{action:'getProvince',keys:$(this).val()},function(data){
            _ds = data.key;
            _html = '<li class="itemLi odd selected" data="'+_ds+'"><ul class="topUl">';
            _html +='<ul class="topUl">';
            _html +='<li class="tcol_1 tcol">'+data.title+'</li>';
            _html +='<li class="tcol_2 tcol">';
            _html +='</li>';
            _html +='</ul>';
            _html +='<div class="botW clearfix">';
            _html +='<table class="table">';
            _html +='<thead>'
            _html +='<tr>';
            _html +='<th class="tbcol tbcol_1">地点</th>';
            _html +='<th class="tbcol tbcol_2">代理商账号</th>';
            _html +='</tr>';
            _html +='</thead>';
            _html +='<tbody>';
            
            for(var i in data.city){
                _html +='<tr>';
                _html +='<input type="hidden" name="city_code[]" value="'+data.city[i].code+'"/>';
                _html +='<td class="tname tbcol_1">'+data.city[i].ctitle+'</td>';
                _html +='<td data="'+_ds+'" class="agent_se" agent="'+data.city[i].inviter+'">';
                _html +=$("#hideSetion").html();
                _html +='</td>';
                _html +='</tr>';
            }
            _html +='</tbody>';
            _html +='</table>';
           // _html +='<a href="#" class="slideUpBtn"><i class="i">︽</i>收起</a>';
            _html +='</div>';
            _html +='</li>';
			_html +='<li><input type="submit" class="d_save" value="保存"></li>';
             $(".listWrap").html(_html);
             $(".list-agent").hide();

            $(".agent_se").each(function(idx,element){
                if($(this).attr("data")==_ds && $(this).attr("agent")){
                    $(this).find(".agents").val(Number($(this).attr("agent")));
                }
            });
        });
    });
});
</script>
<?include("common/footer.html");?>